package com.trkj.service.cf;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.cf.DefinepositionDAO;
import com.trkj.pojo.Organization;
import com.trkj.pojo.Position;
import com.trkj.service.ServiceException;

@Service
@Transactional(rollbackFor=Exception.class)
public class DefinepositionSrevice {
		@Autowired
		private DefinepositionDAO definepositionDAO;
	public long pageCount() {
		return definepositionDAO.count();
	}
	// 分页 定义职位
		public List<Position> Page(Integer page, Integer rows) throws ServiceException {
			try {
				List<Position> list = definepositionDAO.queryByPage(new PageRequest(page - 1, rows));
				return list;
			} catch (Exception e) {
				e.printStackTrace();
				throw new ServiceException(e.getMessage());
			}
		}
			// 新增
			public void definepositionadd(String positionName,String positionRemark) throws ServiceException {
				System.out.println(positionName);
				try {
					Date date = new Date();
					Position o = new Position();
					// o.setOrganiId(organsId);
					o.setPositionName(positionName);
					o.setPositonCreatordate(new Timestamp(date.getTime()));
					o.setPositionRemark(positionRemark);
					definepositionDAO.save(o);
				} catch (Exception e) {
					e.printStackTrace();
					throw new ServiceException(e.getMessage());
				}
			}
			// 编辑
	public void definepositionupdate(Long positionId, String positionName, String positionRemark) throws ServiceException {
		try {
			Position or = definepositionDAO.findOne(positionId);
			Date date = new Date();
			 or.setPositionName(positionName);
			 or.setPositionRemark(positionRemark);
			or.setPositionUpdatedate(new Timestamp(date.getTime()));
			definepositionDAO.save(or);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	//删除
	public void definepositionremove(Long positionId) {
		definepositionDAO.delete(positionId);
	}
	//搜索
	public List<Position> filedByName(String positionName) {
		
		return definepositionDAO.queryByPositionName("%"+positionName+"%");
	}
	 
	 
}
